﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace RBS.Web.Hotel.Controllers
{
    public class HomeController : BaseController
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
           if (!User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index", "Login");
            }
            else
            { 
               /* if (CurrentUser.HotelId == 0)
                {
                    return RedirectToAction("Index", "Home");
                } 
                ViewBag.UserName = CurrentUser.H_UserName;*/
                ViewBag.UserName = CurrentUser.H_UserName;
                ViewBag.RoleIds = CurrentUser.RoleIds;
                ViewBag.Title = "酒店管理平台" + CurrentUser.H_UserName;
             
                return View();
            }  
        }  
        public ActionResult Logout()
        {
            FormsAuthentication.SignOut(); 
            Session.Abandon();
            return RedirectToAction("Index", "Login");
        }

        //
        // GET: /Home/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }
        public ActionResult UpdatePassWord()
        {
            var model = CurrentUser;
            return View(model);
        } 
        [HttpPost]
        public ActionResult UpdatePassWord(FormCollection collection)
        {
            var model = CurrentUser; 
            model.Password = collection["txtPassword1"]; 
            return View();
        } 
        //
        // GET: /Home/Create

        public ActionResult Main()
        {
             if (CurrentUser.HotelId == 0)
               {
                   return RedirectToAction("HotelEdit", "Hotel");
               }
             ViewBag.Hotel = new RBS.Core.BLL.Hotel.H_Hotels().GetModelByCache(CurrentUser.HotelId);
             ViewBag.UserName = CurrentUser.H_UserName; 
            return View();
        } 

        //
        // POST: /Home/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Home/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Home/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Home/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Home/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
